<?php 
//Xử lý xóa
if(isset($_POST['XOA']))
{
	$id=$_POST['id'];
	$sql="DELETE FROM dp_news WHERE id='$id'";
	mysql_query($sql);
	header("Location: index.php?option=thongbao");
}
if(isset($_POST['HUY']))
{
	header("Location: index.php?option=thongbao");
}
//Xử lý thêm tin
if(isset($_POST['DANG']))
{
	$title=$_POST['title'];
	$summany=$_POST['summany'];
	$content=$_POST['content'];
	$linkfile=$_FILES['linkfile']['name'];
	$image=$_FILES['image']['name'];
	$author=$_POST['author'];
	$states=$_POST['states'];
	$d=getdate();
    $time=gmdate("h:i:s", time()+7*3600);
    $datepost=$d['year']."-".$d['mon']."-".$d['mday'];
	$sqlinsert="INSERT INTO dp_news(title,summany,content,image,datepost,author,states,linkfile)
	VALUES('$title','$summany','$content','$image','$datepost','$author','$states','$linkfile')";
	mysql_query("SET NAMES utf8");
	mysql_query($sqlinsert);
///upload hình
    move_uploaded_file($_FILES['linkfile']['tmp_name'],"../../12/images/thongbao/".$linkfile);
	move_uploaded_file($_FILES['image']['tmp_name'],"../../12/images/thongbao/".$image);
	header("Location: index.php?option=thongbao");
}
if(isset($_POST['CAPNHAT']))
{
	$ip=$_POST['id'];
	$title=$_POST['title'];
	$summany=$_POST['summany'];
	$content=$_POST['content'];
	$image=$_FILES['image']['name'];
	$image=$_FILES['linkfile']['name'];
	$states=$_POST['states'];
	$strupdate="title='$title',summany='$summany',content='$content', states='$states'";
	if(strlen($image)!=0)
	{
		$sqltmp="SELECT * FROM dp_news WHERE id='$id'";
		$tam=$dp->QueryOne($sqltmp);
		if(file_exists("../../12/images/thongbao/".$tam['image']))
		{
			unlink("../../12/images/thongbao/".$tam['image']);
		}
		move_uploaded_file($_FILES['image']['tmp_name'],"../../12/images/thongbao/".$image);
		$strupdate.=", image='$image'";
	}
	$sql="UPDATE dp_news SET $strupdate WHERE id='$id'";
	
	//echo $sql;
	mysql_query("SET NAMES utf8");
	mysql_query($sql);
	header("Location: index.php?option=thongbao");
}
?>